﻿
Public MustInherit Class producer
    Implements iproducer

    Private targetQueue As jobqueue = Nothing

    Public Sub start(ByVal targetQueueName As String) Implements iproducer.start
        assert(Not isemptystring(targetQueueName))
        targetQueue = jobqueues.at(targetQueueName)
    End Sub

    Public MustOverride Sub [stop]() Implements iproducer.stop

    Protected Function ijobStep(ByVal job As ijob,
                                ByVal [goto] As _do(Of Boolean),
                                Optional ByRef indexedJob As indexedJob = Nothing) As _do(Of Boolean)
        Return share.ijobStep(job, targetQueue, [goto], indexedJob)
    End Function

    Protected Function ijobEventComb(ByVal job As ijob,
                                     Optional ByRef indexedJob As indexedJob = Nothing) As eventComb
        Return share.ijobEventComb(job, targetQueue, indexedJob)
    End Function

    Public Shared Function initial(ByVal name As String,
                                   ByVal config As configParser,
                                   ByVal producer As producer) As Boolean
        assert(Not producer Is Nothing)
        Dim s As String = Nothing
        If config.getparameter(name, "targetQueue", s) Then
            producer.start(s)
            Return True
        Else
            raiseError(errorHandle.errorType.user, "no target queue has been set in ", name)
            Return False
        End If
    End Function
End Class
